<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <!-- <el-form-item> -->
        <el-col :xs="24" :sm="12" :md="12" :lg="12">
          <el-input size="small" type="textarea" style="width:100%;" rows="1" resize="both" v-model.trim="filters.sql" placeholder="请输入Sql"></el-input>
        </el-col>
        <!-- </el-form-item> -->
        <!--  <el-form-item style="float:right;">
            <el-button size="small" type="primary"  icon="upload2" @click="exportExcels">导出</el-button>
          </el-form-item> -->
        <el-form-item style="float:right;">
          <!--  <el-button size="small" style="width:60px;height:28px;background:#f5fbff;border-color:#f5fbff;" v-on:click="getpass"></el-button> -->
          <el-button size="small" type="primary" icon="search" v-show="sqlQuery" v-on:click="getLogs(true)">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table :data="Logs" stripe border :height="winHeight-120" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column prop="ID" align="center" label="ID" width="80">
      </el-table-column>
      <el-table-column prop="" align="center" label="内容" min-width="60" :formatter="formatContent" show-overflow-tooltip>
      </el-table-column>
      <!-- <el-table-column prop="businessNo" align="center" label="订单号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="userCode" align="center" label="客户编码" width="120">
      </el-table-column>
      <el-table-column prop="phoneNo" align="center" label="客户手机号" min-width="130" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="status" align="center" label="状态" width="120" :formatter="formatStatus">
      </el-table-column>
      <el-table-column prop="money" align="center" label="金额" min-width="100">
      </el-table-column>
      <el-table-column prop="score" align="center" label="积分" min-width="100">
      </el-table-column>
      <el-table-column prop="rate" align="center" label="兑换比例" min-width="120">
      </el-table-column>
      <el-table-column prop="createTime" align="center" label="提现时间" min-width="120" show-overflow-tooltip :formatter="formatCreateTime">
      </el-table-column>
      <el-table-column prop="payeepayee" align="center" label="收款人姓名" min-width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="idcard" align="center" label="身份证号" min-width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="currency" align="center" label="币种" min-width="100" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="payeeBank" align="center" label="收款银行" min-width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="payeeAccount" align="center" label="收款银行账号" min-width="130" show-overflow-tooltip>
      </el-table-column> -->
      <el-table-column label="操作" fixed='right' width="80">
        <template scope="scope">
          <el-button size="small" @click="handleDetail(scope.$index, scope.row)">详情</el-button>
          <!-- <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <!-- <el-col :span="24" class="toolbar"> -->
    <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
    <!--
      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout=" prev, pager, next" :total="total">
      </el-pagination>
    </el-col> -->

    <!--详情界面-->
    <el-dialog title="详情" v-model="detailFormVisible" :close-on-click-modal="false">
      <el-form :model="detailForm" label-width="100px" ref="detailForm">
        <div>
          <span>详情信息:</span>
          <span style="word-wrap:break-word">{{detailForm.content}}</span>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="detailFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <!--匹配界面-->
    <el-dialog title="匹配" size="tiny" v-model="matchFormVisible" :close-on-click-modal="false">
      <el-form :model="matchForm" label-width="100px" ref="matchForm" :rules="matchFormRules" :inline="true">
        <el-form-item>
          <el-input size="small" style="width:200px;" v-model.trim="matchForm.matchCode" placeholder="请输入匹配码"></el-input>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button size="small" type="primary" v-on:click="match(matchForm.matchCode)">匹配</el-button>
        </el-form-item>
        <el-card class="box-card" v-show="uploadPass">
          <el-row>
            <el-col :xs="24" :sm="24" :md="24" :lg="24">
              <el-form-item label="用户编码:" prop="userCode">
                <el-input v-model="matchForm.userCode" auto-complete="off" placeholder="请输入用户编码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :md="24" :lg="24">
              <el-form-item label="密码:" prop="password">
                <el-input v-model="matchForm.password" auto-complete="off" placeholder="请输入密码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col align="center">
              <el-button type="primary" @click.native="matchSubmit" :loading="matchLoading">提交</el-button>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
    </el-dialog>
  </section>
</template>

<script>
import util from '../../common/js/util'

import commons from '../../common/js/common'
//import NProgress from 'nprogress'
import { mapState, mapActions } from 'vuex'
import { findBySql, updatePwdByUserCode } from '../../api/api';

export default {
  data() {
    return {
      filters: {
        sql: ''
      },
      Logs: [],
      lists: [],
      exportTotal: 0,
      total: 0,
      page: 1,
      pageSize: 10,
      loading: '',
      // fullscreenLoading:false,
      listLoading: false,
      addLoading: false,
      matchLoading: false,
      addFormVisible: false,
      detailFormVisible: false,
      matchFormVisible: false,
      sqlQuery: false,
      sels: [],//列表选中列
      userid: '',
      addFormRules: {

      },
      matchFormRules: {
        userCode: [
          { required: true, message: '请输入用户编码', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      detailForm: {
        content: ''
      },
      matchForm: {
        matchCode: '',
        userCode: '',
        password: ''
      },
      IsShow: false,
      uploadPass: false
    }
  },
  computed: mapState([
    'winWidth',
    'winHeight'
  ]),
  methods: {
    cellStyle(row, rowIndex, columnIndex) {
    },
    formatContent: function (row, column) {
      return JSON.stringify(row);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getLogs(true);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getLogs(true);
    },
    //获取列表
    getLogs(bool) {
      let para = new FormData();
      // para.append("pageSize",bool?this.pageSize:this.exportTotal);
      // para.append("pageNumber",bool?this.page:1);
      para.append("sql", this.filters.sql);
      this.listLoading = bool;
      // this.fullscreenLoading = bool?false:true;
      if (!bool) {
        this.loading = this.$loading({
          lock: true,
          text: '正在导出',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      }
      findBySql(para).then((res) => {
        this.listLoading = false;
        if (!bool) {
          this.loading.close();
          this.export2Excel();
        }
        else {
          this.Logs = res.data.result;
        }
      });
    },
    getpass() {
      this.matchFormVisible = true;
      this.matchForm = {
        matchCode: '',
        userCode: '',
        password: ''
      };
      this.uploadPass = false;
      this.$refs['matchForm'].resetFields();
    },
    match: function (code) {
      if (code == "000000") {
        this.uploadPass = true;
      }
      else {
        this.$message({
          message: "匹配失败",
          type: 'error'
        });
      }
      this.matchForm.matchCode = "";
    },
    matchSubmit: function () {
      this.$refs.matchForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.matchLoading = true;
            let para = new FormData();
            para.append("userCode", this.matchForm.userCode);
            para.append("password", this.matchForm.password);
            updatePwdByUserCode(para).then((res) => {
              if (res.data.success) {
                this.$message({
                  message: res.data.result,
                  type: 'success'
                });
                this.matchFormVisible = false;
                this.$refs['matchForm'].resetFields();
              }
              else {
                this.$message({
                  message: res.data.result,
                  type: 'error'
                });
              }
              this.matchLoading = false;
            }).catch(() => {
              this.matchLoading = false;
            });
          });
        }
      });
    },
    //详情
    handleDetail: function (index, row) {
      this.detailFormVisible = true;
      this.detailForm.content = JSON.stringify(row);
    },
    //table导出excel
    exportExcels: function () {
      this.getLogs(false);
    },
    export2Excel: function () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['ID', '订单号', '客户编码', '客户手机号', '状态', '金额', '积分', '兑换比例', '提现时间', '收款人姓名', '身份证号', '币种', '收款银行', '收款银行账号'];
        const filterVal = ['id', 'businessNo', 'userCode', 'phoneNo', 'status', 'money', 'score', 'rate', 'createTime', 'payeepayee', 'idcard', 'currency', 'payeeBank', 'payeeAccount'];
        const list = this.lists;
        for (var i in list) {

          list[i].createTime = commons.getDaytime(list[i].createTime, 1, false);
          list[i].status = commons.payeeStatus(list[i].changeType);
        }
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '提现明细列表');
      })
    },
    formatJson: function (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    btnShow: function () {
      let thisData = JSON.parse(sessionStorage.getItem('158'));
      let _this = this;
      $.each(thisData, function (i, j) {
        if (thisData[i] == "sqlQuery") {
          _this.sqlQuery = true;
        }
      });
    },
  },
  mounted() {
    this.btnShow();
    this.getLogs(true);
  }
}

</script>

<style scoped>

</style>